
$('.addPerson').click(
		function() {
			$.ajax({
				type : "post",
				url : "/userRole/childerList",
				data : {},
				dataType : "json",
				success : function(data) {
					var html = '';
					html += "<ul>";
					for ( var o in data.data) {
						var value = 'data-tag={"id":"' + data.data[o].id
								+ '","name":"' + data.data[o].name + '"}';
						html += '<li class="tag" ' + value
								+ ' onclick="choose(this)">'
								+ data.data[o].name + '</li>';
						// html+="<br>";
						// html+="<li class='tag' data-tag='"+value+"'
						// onclick='choose(this)'>"+data.data[o].name+"</li>";
						// <li class="tag" data-tag='{"id":"1","name":"城西1"}'
						// onclick="choose(this)">城西1</li>
					}
					html += "</ul>";
					$(".memberList").html(html);
					$('.checkPerson p').each(function() {
						var _id = $(this).find('b').data('id');
						$(".memberList li").each(function() {
							if ($(this).data('tag').id == _id) {
								$(this).addClass('disable');
							}
						});
					});
					$('.memberList').stop().show();
				}
			})
		});
$(document).click(function(event) {
	if (event.target.id != $('.addLine').selector.substring(1)) {
		$('.memberList').stop().hide();
	}
});
$('.addLine').click(function(e) {
	e.stopPropagation();
});
function choose(obj) {
	var $clickLi = $(obj);
	var _tag = $clickLi.data('tag');
	if ($clickLi.hasClass('disable')) {
		return false
	}
	$clickLi.addClass('disable');
	var _html = '<p><b data-id="'
			+ _tag.id
			+ '">'
			+ _tag.name
			+ '</b><i class="iconfont icon-shanchu" onclick="delTag(this)"></i></p>'
	$('.checkPerson').append(_html);
	sendVal();
}
function sendVal(){
	var sendArr = [];
	$('.checkPerson p').each(function(){
		sendArr.push($(this).find('b').data('id'));
	});
	$("#sendId").val(sendArr);
	console.log(sendArr);
}
function delTag(obj) {
	var $delObj = $(obj);
	var $delId = $delObj.siblings('b').data('id');
	$('.memberList li').each(function() {
		if ($delId == $(this).data('tag').id) {
			$(this).removeClass('disable');
		}
	})
	$delObj.parent().remove();
	sendVal();
}

$(".sendMC").click(function() {
	var sendId = $("#sendId").val();
	var title = $("#title").val();
	var content = $("#content").val();
	if(sendId == '' || sendId == 'undefind' || sendId == null){
		alert("请选择接收人");
		return false;
	}
	if(title == ''){
		alert("请填写标题");
		return false;
	}
	if(content == ''){
		alert("请填写内容");
		return false;
	}
	$.ajax({
		type : "post",
		url : "/message/addMessage",
		data : {
			"userId" : sendId,
			"title" : title,
			"content" : content
		},
		dataType : "json",
		success : function(data) {
			if (data.status == true) {
				alert("发送消息成功");
				location.reload(); 
			}
		}
	})
})

function recriveDelete(id) {
	$.ajax({
		type : "post",
		url : "/message/updateStatus",
		data : {
			"id" : id
		},
		dataType : "json",
		success : function(data) {
			if (data.status == true) {
				alert(data.data);
				location.reload(); 
			}
		}
	})
}

function deleteMessage(id) {
	$.ajax({
		type : "post",
		url : "/message/deleteMessage",
		data : {
			"id" : id
		},
		dataType : "json",
		success : function(data) {
			if (data.status == true) {
				alert(data.data);
				location.reload(); 
			}
		}
	})
}

var method;
method = function(){
	var pageNo = $("#pageNo").val();
	$.ajax({
		type:"post",
		url:"/message/receiveListQuery",
		data:{"pageNo": pageNo},
		success:function(data){
			$("#mytable").html(data);
		}
	});
}
